package com.group.eams.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.PatentQueryDto;
import com.group.eams.pojo.entity.Patent;
import com.group.eams.pojo.vo.PatentListVo;
import com.group.eams.service.PatentService;
import com.group.result.Result;
import com.group.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 无形资产(专利登记表)(Patent)表控制层
 *
 * @author DHuser
 * @since 2024-10-30 12:58:28
 */
@RestController
@RequestMapping("/patent")
public class PatentController  {
    /**
     * 服务对象
     */
    @Autowired
    private PatentService patentService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/find",method = RequestMethod.GET)
    public Result find(@RequestParam Long id) {
        Patent patent = patentService.getById(id);
        return Result.buildSuccess(patent);
    }

    /**
     * 获取专利登记基础信息
     * @param id
     * @return
     */
    @RequestMapping(value = "/findBasicById",method = RequestMethod.GET)
    public Result findBasicById(@RequestParam Long id) {
        PatentListVo patentListVo = patentService.findBasicById(id);
        return Result.buildSuccess(patentListVo);
    }

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result list(PatentQueryDto patentQueryDto) {
        Page<PatentListVo> page = patentService.findByQueryDto(patentQueryDto);
        return Result.buildSuccess(page.getTotal(),page.getRecords());
    }

    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public Result findAll() {
        List<Patent> list = patentService.list();
        return Result.buildSuccess(list);
    }

    /**
     * 新增数据
     *
     * @param patent 实体对象
     * @return 新增结果
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result add(@RequestBody Patent patent) {
        boolean result = patentService.save(patent);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量新增数据
     * @param patent
     * @return
     */
    @RequestMapping(value = "/addBatch",method = RequestMethod.POST)
    public Result addBatch(@RequestBody List<Patent> patent) {
        boolean result = patentService.saveBatch(patent);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 修改数据
     *
     * @param patent 实体对象
     * @return 修改结果
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result update(@RequestBody Patent patent) {
        boolean result = patentService.updateById(patent);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量修改数据
     * @param patent
     * @return
     */
    @RequestMapping(value = "/updateBatch",method = RequestMethod.POST)
    public Result updateBatch(@RequestBody List<Patent> patent) {
        boolean result = patentService.updateBatchById(patent);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public Result delete(@RequestParam Long id) {
        boolean result = patentService.removeById(id);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量删除数据
     * @param batchDeleteDto
     * @return
     */
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    public Result deleteBatch(@RequestBody List<Long> batchDeleteDto) {
        boolean result = patentService.removeByIds(batchDeleteDto);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }
    
}

